#include "MaSocketClient.h"

MaSocketClient::MaSocketClient(QTcpSocket *socket, Client *parent) : MaSocket(socket, parent)
{
    connect(this, SIGNAL(connexionAcceptee()), parent, SLOT(connexionAcceptee()));
    connect(this, SIGNAL(connexionRefusee(QString)), parent, SLOT(connexionRefusee(QString)));
    connect(this, SIGNAL(recevoirEnvoyerATous(QString)), parent, SLOT(recevoirEnvoyerATous(QString)));
}

void MaSocketClient::traitementMessage(quint8 typeApplication, quint8 typeMessage, QByteArray contenu)
{
    QDataStream in(contenu);
    switch(typeApplication)
    {
    case NOYAU:
        {
            switch(typeMessage)
            {
            case CONNEXION_ACCEPTEE:
                {
                    emit connexionAcceptee();
                    break;
                }
            case CONNEXION_REFUSEE:
                {
                    QString message;
                    in >> message;
                    emit connexionRefusee(message);
                    break;
                }
            }
            break;
        }
    case CHAT:
        {
            switch(typeMessage)
            {
            case RECEVOIR_ENVOYER_A_TOUS:
                {
                    QString message;
                    in >> message;
                    emit recevoirEnvoyerATous(message);
                    break;
                }
            }
            break;
        }
    }
}

